//package com.life.notes.config.utils;
//
//import com.csvreader.CsvWriter;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.OutputStream;
//import java.nio.charset.Charset;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author lishuqian
// * @date 2020/6/15
// */
//public class CsvUtil {
//
//    public CsvUtil() {
//    }
//
//    public static void exportCsv(HttpServletResponse httpServletResponse, List<Map<String, Object>> exportDatas, String[] headers, String[] headerKeys) {
//        try {
//            File tempFile = createTempFile(exportDatas, headers, headerKeys);
//            outCsvStream(httpServletResponse, tempFile);
//            deleteFile(tempFile);
//        } catch (IOException var5) {
//            System.out.println("导出失败");
//        }
//
//    }
//
//    public static File createTempFile(List<Map<String, Object>> exportDatas, String[] headers, String[] headerKeys) throws IOException {
//        File tempFile = File.createTempFile("vehicle", ".csv");
//        CsvWriter csvWriter = new CsvWriter(tempFile.getCanonicalPath(), ',', Charset.forName("UTF-8"));
//        csvWriter.writeRecord(headers);
//        Iterator var5 = exportDatas.iterator();
//
//        while(var5.hasNext()) {
//            Map<String, Object> data = (Map)var5.next();
//            String[] var7 = headerKeys;
//            int var8 = headerKeys.length;
//
//            for(int var9 = 0; var9 < var8; ++var9) {
//                String headerKey = var7[var9];
//                csvWriter.write((String)data.get(headerKey));
//            }
//
//            csvWriter.endRecord();
//        }
//
//        csvWriter.close();
//        return tempFile;
//    }
//
//    public static void outCsvStream(HttpServletResponse response, File tempFile) throws IOException {
//        OutputStream out = response.getOutputStream();
//        byte[] b = new byte[10240];
//        File fileLoad = new File(tempFile.getCanonicalPath());
//        response.reset();
//        response.setContentType("application/csv");
//        response.setHeader("content-disposition", "attachment; filename=export.csv");
//        FileInputStream in = new FileInputStream(fileLoad);
//        out.write(new byte[]{-17, -69, -65});
//
//        int n;
//        while((n = in.read(b)) != -1) {
//            out.write(b, 0, n);
//        }
//
//        in.close();
//        out.close();
//    }
//
//    public static boolean deleteFile(File file) {
//        if (file.exists() && file.isFile()) {
//            return file.delete();
//        } else {
//            return false;
//        }
//    }
//}
